package LeetCode;

class missingNumber {
    public int missingNumber(int[] nums) {
        int n = nums.length;
        //先算出0~n的数字之和
        int result = (n+1)*n / 2;
        int tmp = 0;
        for(int i = 0;i < n;i++) {
            tmp += nums[i];
        }
        //迭代算出数组之和
        //应有数字之和减去数组之和即为解
        result = result - tmp;
        return result;

    }
}